#!/bin/bash
 echo alias bond0 bonding>>/etc/modprobe.d/bonding.conf
 echo options bond0 miimon=100 mode=6>>/etc/modprobe.d/bonding.conf
 cd /etc/sysconfig/network-scripts/
 ETH1=$(ifconfig |head -1|awk '{print $1}')
 ETH11=$(echo $ETH1|wc -L)
 (( ETH12 = $ETH11 - 1 ))
 ETH21=$(echo ${ETH1:$ETH12})
 (( ETH22 = $ETH21 + 1 ))
 ETH2=$(echo ${ETH1:0-$ETH11:$ETH12}"$ETH22")
mv /etc/sysconfig/network-scripts/ifcfg-$ETH1 /etc/sysconfig/network-scripts/ifcfg-$ETH1.bak
mv /etc/sysconfig/network-scripts/ifcfg-$ETH2 /etc/sysconfig/network-scripts/ifcfg-$ETH2.bak
cp /etc/sysconfig/network-scripts/ifcfg-$ETH1.bak /etc/sysconfig/network-scripts/ifcfg-bond0
sed -i '/HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-bond0
sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-bond0
sed -i '/DEVICE/d' /etc/sysconfig/network-scripts/ifcfg-bond0
echo -e "DEVICE=bond0" >>/etc/sysconfig/network-scripts/ifcfg-bond0
cat >> /etc/sysconfig/network-scripts/ifcfg-$ETH1<<EOF
DEVICE=$ETH1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
EOF

cat >> /etc/sysconfig/network-scripts/ifcfg-$ETH2<<EOF
DEVICE=$ETH2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
EOF

#reboot